/**
 * Copyright [2019] [LiBo/Alex of copyright liboware@gmail.com ]
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.hyts.dess.stateful.egine.service.impl;

import com.hyts.dess.base.tools.ExecutionTemplate;
import com.hyts.dess.base.tools.FunctionTemplate;
import com.hyts.dess.bean.req.DessRequest;
import com.hyts.dess.bean.resp.DessResponse;
import com.hyts.dess.stateful.egine.core.StateFlowProcessor;
import com.hyts.dess.stateful.egine.service.StateMachineService;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import java.util.Objects;

/**
 * @project-name:dess
 * @package-name:com.hyts.dess.stateful.egine.service.impl
 * @author:LiBo/Alex
 * @create-date:2020-06-24 9:20
 * @copyright:libo-alex4java
 * @email:liboware@gmail.com
 * @description:
 */
@Slf4j
@NoArgsConstructor
@AllArgsConstructor
public class DefaultStateMachineService implements StateMachineService {

    /**
     * 状态流转控制处理器
     */
    StateFlowProcessor stateFlowProcessor;

    /**
     * 状态流转服务功能实现
     * @param request
     * @return
     */
    @Override
    public DessResponse flowState(DessRequest request) {
        Objects.requireNonNull(stateFlowProcessor,"状态流转控制处理器操作对象不允许为空!");
        log.info("流转状态处理控制路径进行初始化以及进行扩展延申。");
        // 执行引擎操作对象模板方法处理器
        ExecutionTemplate<DessRequest,DessResponse> functionTemplate = new ExecutionTemplate<DessRequest,DessResponse>() {
            @Override
            public boolean preHandle(DessRequest... args) {
                Objects.requireNonNull(args,"校验请求参数是否为空!");
                return false;
            }
            @Override
            public DessResponse process(DessRequest... args) {
                return null;
            }
            @Override
            public boolean postHandle(DessRequest... args) {
                return false;
            }
            @Override
            public void throwHandle(Throwable throwable) {

            }
        };
        return functionTemplate.execute(request);
    }

}
